<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport"
	content="user-scalable=no, initial-scale=1.0, maximum-scale=1.0" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<script src="../public/lobster/js/public.js"></script>
<link rel="stylesheet" type="text/css"
	href="../public/lobster/icon/iconfont.css">
<link rel="stylesheet" href="../public/lobster/css/public.css">
<link rel="stylesheet" href="../public/lobster/css/shared.css">
<link rel="stylesheet" href="../public/lobster/css/href.css?20170421">
<title>退货</title>
</head>
<body class="withdrawals">
	<!--页头-->
	<!--页头-->
	<header class="header_wallet">
	<div class="wallet_font">我的现金（元）</div>
	<div class="wallet_mon" id='MyMoney'>
		4.26
	</div>
	</header>

	<!--主体-充值，退货，记录-->
	<div class="select">
		<ul>
			<li><input placeholder="请输入退货金额" id="money" /> <i
				class="iconfont icon-zhifubaozhanneidaeshoufukuan"></i></li>
			<li><input placeholder="请输入持卡人姓名" id="name" /> <i
				class="iconfont icon-renwu"></i></li>
			<li><select id="op_bank" name="bank">
					<option value="0">请选择银行</option>
					<option value="1">工商银行</option>
					<option value="2">建设银行</option>
					<option value="4">农业银行</option>
					<option value="6">招商银行</option>
					<option value="3">中国银行</option>
					<option value="5">交通银行</option>
			</select> <i class="iconfont icon-yinxing"></i></li>

			


			<li><input placeholder="请输入卡号" id="cardNo" /> <i
				class="iconfont icon-yinxingqia"></i></li>
		</ul>
	</div>
	<button type="button" class="row_btn" onclick="FormSubmit()">立
		刻 退 货</button>
	</section>





	
	<!--底部导航栏-->
	<nav class="nav">
	<ul id="list">
		<li><a href="index.html"> <img
				src="../public/lobster/images/navbar01.png" alt="">
		</a></li>
		<li><a href="lotteryInfo.html"> <img
				src="../public/lobster/images/navbar02.png" alt="">
		</a></li>
		<li><a href="center.html"> <img
				src="../public/lobster/images/onnavbar03.png" alt="">
		</a></li>
	</ul>
	</nav>

</body>
<script src="../public/lobster/js/jq-2.1.0.js"></script>

<script type="text/javascript">

//验证银行号码
function luhmCheck(bankno){
    		if (bankno.length<16|| bankno.length >19) {
    			$("#span").html("<font color='red' size='5px'>银行卡号长度必须在16到19之间!</font>");
    			return false;
    		}
    		var num = /^\d*$/;  //全数字
    		if (!num.exec(bankno)) {
    			return false;
    		}
    		//开头6位
    		var strBin="10,18,30,35,37,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,58,60,62,65,68,69,84,87,88,94,95,98,99";    
    		if (strBin.indexOf(bankno.substring(0, 2))== -1) {
    			//alert("银行卡号开头6位不符合规范");
    			$("#span").html("<font color='red' size='5px'>银行卡号开头6位不符合规范!</font>");
    			return false;
    		}
            var lastNum=bankno.substr(bankno.length-1,1);//取出最后一位（与luhm进行比较）
        
            var first15Num=bankno.substr(0,bankno.length-1);//前15或18位
            var newArr=new Array();
            for(var i=first15Num.length-1;i>-1;i--){    //前15或18位倒序存进数组
                newArr.push(first15Num.substr(i,1));
            }
            var arrJiShu=new Array();  //奇数位*2的积 <9
            var arrJiShu2=new Array(); //奇数位*2的积 >9
            
            var arrOuShu=new Array();  //偶数位数组
            for(var j=0;j<newArr.length;j++){
                if((j+1)%2==1){//奇数位
                    if(parseInt(newArr[j])*2<9)
                    arrJiShu.push(parseInt(newArr[j])*2);
                    else
                    arrJiShu2.push(parseInt(newArr[j])*2);
                }
                else //偶数位
                arrOuShu.push(newArr[j]);
            }
            
            var jishu_child1=new Array();//奇数位*2 >9 的分割之后的数组个位数
            var jishu_child2=new Array();//奇数位*2 >9 的分割之后的数组十位数
            for(var h=0;h<arrJiShu2.length;h++){
                jishu_child1.push(parseInt(arrJiShu2[h])%10);
                jishu_child2.push(parseInt(arrJiShu2[h])/10);
            }        
            
            var sumJiShu=0; //奇数位*2 < 9 的数组之和
            var sumOuShu=0; //偶数位数组之和
            var sumJiShuChild1=0; //奇数位*2 >9 的分割之后的数组个位数之和
            var sumJiShuChild2=0; //奇数位*2 >9 的分割之后的数组十位数之和
            var sumTotal=0;
            for(var m=0;m<arrJiShu.length;m++){
                sumJiShu=sumJiShu+parseInt(arrJiShu[m]);
            }
            
            for(var n=0;n<arrOuShu.length;n++){
                sumOuShu=sumOuShu+parseInt(arrOuShu[n]);
            }
            
            for(var p=0;p<jishu_child1.length;p++){
                sumJiShuChild1=sumJiShuChild1+parseInt(jishu_child1[p]);
                sumJiShuChild2=sumJiShuChild2+parseInt(jishu_child2[p]);
            }      
            //计算总和
            sumTotal=parseInt(sumJiShu)+parseInt(sumOuShu)+parseInt(sumJiShuChild1)+parseInt(sumJiShuChild2);
            
            //计算Luhm值
            var k= parseInt(sumTotal)%10==0?10:parseInt(sumTotal)%10;        
            var luhm= 10-k;
            
            if(lastNum==luhm){
            return true;
            }
            else{
    			$("#span").html("<font color='red' size='5px'>银行卡号不正确!</font>");
            return false;
            }        
        }
	function FormSubmit(){

		var d=new Date(); 
		var xq=d.getDay();		//获取当前时间星期几
		var h=d.getHours();		
		
		if(xq>=1 && xq<=5 && parseInt(h)>=08 && parseInt(h)<=23){
			//我的金额
			var MyMoney = parseFloat($("#MyMoney").html().trim());
			//输入金额
			var $money = $("#money");
			var money = parseFloat($money.val().trim());

			if(money>MyMoney){
				xxone.popup("提示","退货金额最大允许"+MyMoney,"确认");
				$('#xxone-popup-done').bind('click',function(){
					$money.val(MyMoney);
				  });
				
				return;
			}
			//银行卡号
			var cardId= $("#cardNo").val();
			
			if(!luhmCheck(cardId)){
				xxone.popup("提示","请输入正确的银行卡号","确认");
				return ;
			}
			//银行
			var bank=$("#op_bank").val();
			//请输入持卡人姓名
			var name=$("#name").val();
			
			if(isNaN(money)){
				xxone.popup("提示","请正确输入退货金额","确认");
				return;
			}
			if(money<10){
				xxone.popup("提示","每次退货金额不能少于10元","确认");
				return;
			}
			if(bank == 0){
				xxone.popup("提示","请选择银行","确认");
				return;
			}
			if(name.length == 0){
				xxone.popup("提示","请输入持卡人姓名","确认");
				return;
			}
			if(cardId.length < 15){
				xxone.popup("提示","银行卡卡号不正确 ","确认");
				return;
			}
			$.ajax({
	    		type:"POST",
	    		url: "/user/Verification?v="+Math.random(),
	    		data:{},
	    		dataType:"json",
	    		success:function(data){
	    			if(data == true){
	    				xxone.popup("提示","未实名认证用户无法退货","确认");
	    				$('#xxone-popup-done').bind('click',function(){
	    					window.location.href="/user/SMRZ";
	    				  });
		    			
		    			return;
	    			}else{
	    				$.ajax({
				    		type:"POST",
				    		url: "/a2p/OutMoneyApply?v="+Math.random(),
				    		data:{
				    			"cardId":cardId,
				    			"name":name,
				    			"bank":bank,
				    			"money":money
				    		},
				    		dataType:"json",
				    		success:function(data){
				    			if(data.success){
				    				xxone.popup("提示","退款申请成功","确认");
				    				$('#xxone-popup-done').bind('click',function(){
				    					window.location.href="/user/center";
				    				  });
					    			
				    			}else{
				    				
				    				xxone.popup("提示",data.msg,"确认");
				    				$('#xxone-popup-done').bind('click',function(){
				    					window.location.reload();
				    				  });
				    				
				    			}
				    		}
						});
	    			}
	    		}
			}); 
			}else{
				 xxone.popup("提示","“提现”时间段:<br/>周一至周五：08:00 - 23:00。");
			}
			
	}

	
	$("#bd_bank").bind("change",function(e){
		/* var target=e|e.target;
		console.log(target); */
		var id = $("#bd_bank").val();
		console.log(id);
		if(id != "0"){
			$.ajax({
	    		type:"POST",
	    		url: "/user/getBank?v=" + Math.random(),
				data : {
					"id" : id
				},
				dataType : "json",
				success : function(data) {
					//姓名
					$("#name").val(data.result.username);
					//银行类型
					$("#op_bank").val(data.result.bankType).attr("selected");
					//卡号
					$("#cardNo").val(data.result.cardId);
				}
			});
		} else {
			$("#name").val("");
			$("#op_bank").val('0').attr("selected");
			$("#cardNo").val("");
		}
	});
</script>

</html>